<template>
	<view class="" v-if="info.id" style="padding-bottom: 200rpx;">



		<view style="background:#f3f4f6" class="p15">

			<u-swiper @change="bannerChange" @click="toBanner(curBanner)" name="picUrl" :list="info.sliderPicUrls"
				height="400">
			</u-swiper>
		</view>

		<view class="p15">
			<view class="fz14 pb10">
				标题
			</view>
			<view style="background: rgba(25,41,28,0.05);" class="brs5 p10">
				<input placeholder="请输入标题" v-model="form.title" type="text" style="padding: 0;" />
			</view>

			<view class="fz14 pb10 mt15">
				正文
			</view>
			<view style="background: rgba(25,41,28,0.05);" class="brs5 p10">
				<textarea v-model="form.content" style="min-height:100px;width:100%" auto-height
					placeholder="请输入正文内容"></textarea>
			</view>
		</view>




		<view class="fixed-bottom p15 bt">
			<view class="btn-sure" @click="toShare">立即发布</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isDisabled: false,
				info: {},
				form: {
					title: '',
					content: '',
				}

			}
		},

		onLoad(e) {
			this.getInfo(e.id)
		},
		onShow() {},

		methods: {
			toShare() {
				if (this.isDisabled) {
					return
				}
				this.isDisabled = true
				this.$api.communityAdd({
					compositionId: this.info.id,
					title: this.form.title,
					content: this.form.content
				}, res => {
					if (res.code == 200) {
						this.$common.successToShow('发布成功', ress => {

							uni.switchTab({
								url: '/pages/community/index'
							})
							this.isDisabled = false
						})
					} else {
						this.isDisabled = false
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				})

			},
			toEdit() {

				uni.navigateTo({
					url: '/pages/diy/index?diyId=' + this.info.id
				})
			},
			toList() {
				uni.navigateTo({
					url: '/pages/user/works/index'
				})
			},
			getInfo(id) {
				this.$api.compositionDetail({
					id
				}, res => {
					if (res.code == 200) {
						this.info = res.data
					}
				})
			},


			addCart: function(e) { //加入购物车
				if (!this.curSku.id) {
					uni.showToast({
						title: '请选择规格',
						icon: 'none'
					});
					return
				}
				this.$api.cartAdd({
					skuId: this.curSku.id,
					count: this.skuNum
				}, res => {
					if (res.code == 200) {

						uni.showToast({
							title: '添加成功',
							icon: 'none'
						});
					} else {

						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				})
			},
			buyNow: function() { //立即购买

				if (!this.curSku.id) {
					uni.showToast({
						title: '请选择规格',
						icon: 'none'
					});
					return
				}
				this.$api.buyNow({
					skuId: this.curSku.id,
					count: this.skuNum
				}, res => {
					if (res.code == 200) {
						let ids = res.data
						this.$api.orderCheckSettlement({
							cartIds: ids,
						}, res => {
							if (res.code == 200) {

								uni.navigateTo({
									url: '/pages/product/confirm?cartIds=' + ids
								})
							} else {

								uni.showToast({
									title: res.msg,
									icon: 'none'
								});
							}
						})

					} else {

						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				})

			},
		}
	}
</script>

<style lang="scss">
	.btn-sure {

		width: 100%;
		text-align: center;
		background: #70B52C;
		padding: 24rpx 0;
		font-size: 28rpx;
		color: #FFFFFF;
		border-radius: 10px;
		font-weight: normal;
	}

	.module-btn {
		padding: 40rpx;

		.btn {
			background: #70B52C;
			border-radius: 16rpx;
			padding: 24rpx;
			font-size: 28rpx;
			color: #fff;
			margin-top: 24rpx;
		}

		.btn-buy {
			background: #2C9942;
		}
	}
</style>